package com.xiaotao.util;

import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class WsUserSession {
    // 用户id -> sessionId
    private final Map<String, String> userSessionMap = new ConcurrentHashMap<>();

    public void add(String userId, String sessionId) {
        userSessionMap.put(userId, sessionId);
    }

    public String getSessionId(String userId) {
        return userSessionMap.get(userId);
    }

    public void remove(String sessionId) {
        userSessionMap.entrySet().removeIf(entry -> entry.getValue().equals(sessionId));
    }
}
